package cn.stronglink.asset.module.assetmanage.attrvalue.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.stronglink.asset.model.AssetTypeAttrGroup;
import cn.stronglink.asset.model.AssetTypeValue;
import cn.stronglink.asset.module.assetmanage.attrvalue.service.AttrValueService;
import cn.stronglink.asset.module.assetmanage.itasset.vo.ItAssetVo;
import cn.stronglink.asset.module.basicdata.assetTypeAttrGroup.service.AssetTypeAttrGroupService;
import cn.stronglink.suite.core.base.AbstractController;

@Controller
@RequestMapping(value = "asset/attrValue")
public class AttrValueController extends AbstractController {

	@Autowired
	private AssetTypeAttrGroupService assetTypeAttrGroupService;
	@Autowired
	private AttrValueService attrValueService;
	
	/**
	 * 根据资产查询该资产所属的组的属性列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryAttrValue")
	public ResponseEntity<ModelMap> qryAttrValue(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {		
	    List<AssetTypeAttrGroup> data = assetTypeAttrGroupService.qryDetailByTypeId(Long.parseLong(params.get("typeId").toString()));
	    List<AssetTypeValue> attrValues = attrValueService.qryAssetTypeValue(Long.parseLong(params.get("assetId").toString()));
	    modelMap.put("attrValues", attrValues);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 根据资产分类查询动态条件
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryAttrByTypeId")
	public ResponseEntity<ModelMap> qryAttrByTypeId(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {		
	    List<AssetTypeAttrGroup> data = assetTypeAttrGroupService.qryDetailByTypeId(Long.parseLong(params.get("typeId").toString()));
		return setSuccessModelMap(modelMap, data);
	}
	
	
}
